package com.softeem.net;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author xiyu
 * @version 1.0
 * @date 2025/4/8 14:37
 * @description
 */
public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = null;
        Socket sk = null;
        InputStream is = null;
        InputStreamReader isr = null;
        BufferedReader br = null;
        try {
            //创建一个服务器，指定端口
            ss = new ServerSocket(9000);
            //等待客户端链接
            sk = ss.accept();
            //创建输入流
            is = sk.getInputStream();
            //InputStream 字节流-------》InputStreamReader
            isr = new InputStreamReader(is);
            //BufferedRead 字符流readLine()
            br = new BufferedReader(isr);
            String msg = null;
            while (true) {
                msg = br.readLine();
                System.out.println(msg);
                if (msg!=null&&msg.equals("q")){
                    System.exit(0);
                    break;
                }
            }
            //创建文件输出流，写入文件

            br.close();
            isr.close();
            is.close();
            sk.close();
            ss.close();

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
